package com.sc.nft.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sc.nft.entity.PaymentMethod;
import com.sc.nft.enums.PayMethodEnum;
import com.sc.nft.mapper.PaymentMethodMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Objects;

/**
 * 支付方式表(sc_payment_method)数据DAO
 *
 * @author kancy
 * @description 由 Mybatisplus Code Generator 创建
 * @since 2022-06-22 02:14:56
 */
@Slf4j
@Repository
public class PaymentMethodDao extends ServiceImpl<PaymentMethodMapper, PaymentMethod> {

    public List<PaymentMethod> getEffectPayment() {
        LambdaQueryWrapper<PaymentMethod> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(PaymentMethod::getStatus, Boolean.TRUE);
        wrapper.eq(PaymentMethod::getIsAppPay, Boolean.TRUE);
        wrapper.last("order by create_time desc");
        return list(wrapper);
    }

    public List<PaymentMethod> getSecondEffectPayment() {
        LambdaQueryWrapper<PaymentMethod> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(PaymentMethod::getStatus, Boolean.TRUE);
        wrapper.eq(PaymentMethod::getIsSecondPay, Boolean.TRUE);
        wrapper.last("order by create_time desc");
        return list(wrapper);
    }

    public List<PaymentMethod> getTradingPoolPayment() {
        LambdaQueryWrapper<PaymentMethod> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(PaymentMethod::getStatus, Boolean.TRUE);
        wrapper.eq(PaymentMethod::getPayMethod, PayMethodEnum.WALLET_PAY);
        wrapper.last("order by create_time desc");
        return list(wrapper);
    }

    public List<PaymentMethod> getEffectPaymentByIsH5Web() {
        LambdaQueryWrapper<PaymentMethod> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(PaymentMethod::getStatus, Boolean.TRUE);
        wrapper.eq(PaymentMethod::getIsH5Pay, Boolean.TRUE);
        wrapper.last("order by create_time desc");
        return list(wrapper);
    }

    public List<PaymentMethod> listByPayMethod(PayMethodEnum... payMethodEnums) {
        LambdaQueryWrapper<PaymentMethod> wrapper = new LambdaQueryWrapper<>();
        wrapper.in(PaymentMethod::getPayMethod, payMethodEnums);
        wrapper.last("order by create_time desc");
        return list(wrapper);
    }

    public List<PaymentMethod> getPaymentMethodsByRecharge(Boolean isH5) {
        LambdaQueryWrapper<PaymentMethod> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(PaymentMethod::getStatus, Boolean.TRUE);
        wrapper.eq(PaymentMethod::getIsRecharge, Boolean.TRUE);
        if (isH5) {
            wrapper.eq(PaymentMethod::getIsH5Pay, Boolean.TRUE);
        } else {
            wrapper.eq(PaymentMethod::getIsAppPay, Boolean.TRUE);
        }
        wrapper.last("order by create_time desc");
        return list(wrapper);
    }


    public List<PaymentMethod> getPayMethodsByIsH5(Boolean isH5) {
        LambdaQueryWrapper<PaymentMethod> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(PaymentMethod::getStatus, Boolean.TRUE);
        if (isH5) {
            wrapper.eq(PaymentMethod::getIsH5Pay, Boolean.TRUE);
        } else {
            wrapper.eq(PaymentMethod::getIsAppPay, Boolean.TRUE);
        }
        wrapper.last("order by create_time desc");
        return list(wrapper);
    }

    public List<PaymentMethod> getMallEffectPayment(Boolean isH5) {
        LambdaQueryWrapper<PaymentMethod> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(PaymentMethod::getStatus, Boolean.TRUE);
        wrapper.eq(PaymentMethod::getIsMallPay, Boolean.TRUE);
        wrapper.last("order by create_time desc");
        return list(wrapper);
    }

    public List<PaymentMethod> getSecondEquityPropsPayment() {
        LambdaQueryWrapper<PaymentMethod> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(PaymentMethod::getStatus, Boolean.TRUE);
        wrapper.eq(PaymentMethod::getIsSecondPay, Boolean.TRUE);
        wrapper.last("order by create_time desc");
        return list(wrapper);
    }

    public List<PaymentMethod> listByPayMethodParam(List<PayMethodEnum> payMethodEnumList, Boolean isH5Pay, Boolean isAppPay) {
        LambdaQueryWrapper<PaymentMethod> wrapper = new LambdaQueryWrapper<>();
        wrapper.in(PaymentMethod::getPayMethod, payMethodEnumList);
        wrapper.eq(PaymentMethod::getStatus, Boolean.TRUE);
        wrapper.eq(Objects.nonNull(isH5Pay), PaymentMethod::getIsH5Pay, isH5Pay);
        wrapper.eq(Objects.nonNull(isAppPay), PaymentMethod::getIsAppPay, isAppPay);
        wrapper.last("order by create_time desc");
        return list(wrapper);
    }

}